package labox.innovation.gameserver.model;

import java.io.DataOutputStream;
import java.util.HashMap;

import labox.innovation.gameserver.util.StringUtil;
import labox.innovation.gameserver.model.Point;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class WorldScence {

	private int sceneID;		//场景ID
	
	private String name;		//场景名称
	
	private int icon;			//图标

	private int canSelected;	//能否被选
	
	private int sceneLock;	//是否被锁
	
	private int scenePK;		//是否可攻击
	
	private int reviveSceneId;	//复活场景ID
	
	private int revive_X;		//复活场景x
	
	private int revive_Y;		//复活场景Y
	
	private int screenX;		//场景x

	private int screenY;		//场景y
	
	private int teleportX;		//传送场景x
	
	private int teleportY;		//传送场景y
	
	private int sex;			//场景性别限制
	
	private int item;			//场景道具限制
	
	private int classId;		//职业限制
	
	private float exp;			//杀怪经验系数
	
	private int clan;			//所属阵营
	
	private int disc;			//场景描述
	
	private int enableTimer;	//是否使用定时器
	
	private long startTime;		//首次开始时间
	
	private int cycle;			//开放周期
	
	private int cycleUnitLable;	//周期单位 分，时
	
	private int runtime;		//持续时间
	
	private int runtimeUnit;	//持续时间单位
	
	private int teleForPlayer;	//场景关闭时传送玩家

	private int teleSceneId;	//传送到的场景ID
	
	private int teleXforInactive;			//传送到的场景X
	
	public int getIcon() {
		return icon;
	}

	public void setIcon(int icon) {
		this.icon = icon;
	}
	
	public int getTeleXforInactive() {
		return teleXforInactive;
	}

	public void setTeleXforInactive(int teleXforInactive) {
		this.teleXforInactive = teleXforInactive;
	}

	public int getTeleYforInactive() {
		return teleYforInactive;
	}

	public void setTeleYforInactive(int teleYforInactive) {
		this.teleYforInactive = teleYforInactive;
	}

	private int teleYforInactive;			//传送到的场景Y

	public int getSceneID() {
		return sceneID;
	}

	public void setSceneID(int sceneId) {
		sceneID = sceneId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getCanSelected() {
		return canSelected;
	}

	
	public int getScreenX() {
		return screenX;
	}

	public void setScreenX(int screenX) {
		this.screenX = screenX;
	}

	public int getScreenY() {
		return screenY;
	}

	public void setScreenY(int screenY) {
		this.screenY = screenY;
	}
	
	public void setCanSelected(int canSelected) {
		this.canSelected = canSelected;
	}

	public int getSceneLock() {
		return sceneLock;
	}

	public void setSceneLock(int sceneLock) {
		this.sceneLock = sceneLock;
	}

	public int getScenePK() {
		return scenePK;
	}

	public void setScenePK(int scenePk) {
		scenePK = scenePk;
	}

	public int getReviveSceneId() {
		return reviveSceneId;
	}

	public void setReviveSceneId(int reviveSceneId) {
		this.reviveSceneId = reviveSceneId;
	}

	public int getRevive_X() {
		return revive_X;
	}

	public void setRevive_X(int reviveX) {
		revive_X = reviveX;
	}

	public int getRevive_Y() {
		return revive_Y;
	}

	public void setRevive_Y(int reviveY) {
		revive_Y = reviveY;
	}

	public int getTeleportX() {
		return teleportX;
	}

	public void setTeleportX(int teleportX) {
		this.teleportX = teleportX;
	}

	public int getTeleportY() {
		return teleportY;
	}

	public void setTeleportY(int teleportY) {
		this.teleportY = teleportY;
	}

	public int getSex() {
		return sex;
	}

	public void setSex(int sex) {
		this.sex = sex;
	}

	public int getItem() {
		return item;
	}

	public void setItem(int item) {
		this.item = item;
	}

	public int getClassId() {
		return classId;
	}

	public void setClassId(int classId) {
		this.classId = classId;
	}

	public float getExp() {
		return exp;
	}

	public void setExp(float exp) {
		this.exp = exp;
	}

	public int getClan() {
		return clan;
	}

	public void setClan(int clan) {
		this.clan = clan;
	}

	public int getDisc() {
		return disc;
	}

	public void setDisc(int disc) {
		this.disc = disc;
	}

	public int getEnableTimer() {
		return enableTimer;
	}

	public void setEnableTimer(int enableTimer) {
		this.enableTimer = enableTimer;
	}

	public long getStartTime() {
		return startTime;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

	public int getCycle() {
		return cycle;
	}

	public void setCycle(int cycle) {
		this.cycle = cycle;
	}

	public int getCycleUnitLable() {
		return cycleUnitLable;
	}

	public void setCycleUnitLable(int cycleUnitLable) {
		this.cycleUnitLable = cycleUnitLable;
	}

	public int getRuntime() {
		return runtime;
	}

	public void setRuntime(int runtime) {
		this.runtime = runtime;
	}

	public int getRuntimeUnit() {
		return runtimeUnit;
	}

	public void setRuntimeUnit(int runtimeUnit) {
		this.runtimeUnit = runtimeUnit;
	}
	
	public int getTeleForPlayer() {
		return teleForPlayer;
	}

	public void setTeleForPlayer(int teleForPlayer) {
		this.teleForPlayer = teleForPlayer;
	}

	public int getTeleSceneId() {
		return teleSceneId;
	}

	public void setTeleSceneId(int teleSceneId) {
		this.teleSceneId = teleSceneId;
	}

	public final void fromXML(Element e,
			HashMap<Integer, WorldScence> scenePool,
			HashMap<Integer, Point> _pointPool, DataOutputStream dos)
			throws Exception {
		this.setSceneID(Integer.parseInt(e.getAttribute("id")));
		this.setName(e.getAttribute("name"));
		this.setCanSelected(Integer.parseInt(e.getAttribute("selected")));
		this.setSceneLock(Integer.parseInt(e.getAttribute("lock")));
		this.setScenePK(Integer.parseInt(e.getAttribute("pk")));

		this.setTeleportX(Integer.parseInt(e.getAttribute("teleX")));
		this.setTeleportY(Integer.parseInt(e.getAttribute("teleY")));
		this.setSex(Integer.parseInt(e.getAttribute("sex")));
		this.setScreenX(Integer.parseInt(e.getAttribute("screenX")));
		this.setScreenY(Integer.parseInt(e.getAttribute("screenY")));

		this.setClan(Integer.parseInt(e.getAttribute("clan")));

		this.setEnableTimer(Integer.parseInt(e.getAttribute("timer")));
		this.setStartTime(Long.parseLong(e.getAttribute("startTime")));
		this.setCycle(Integer.parseInt(e.getAttribute("cycle")));
		this.setCycleUnitLable(Integer.parseInt(e.getAttribute("cycleUnit")));
		this.setRuntime(Integer.parseInt(e.getAttribute("run")));
		this.setRuntimeUnit(Integer.parseInt(e.getAttribute("runUnit")));
		this.setTeleForPlayer(Integer.parseInt(e.getAttribute("teleforInactive")));
		this.setTeleSceneId(Integer.parseInt(e.getAttribute("tele2SceneforInactive")));
		this.setTeleXforInactive(Integer.parseInt(e.getAttribute("tele2XforInactive")));
		this.setTeleYforInactive(Integer.parseInt(e.getAttribute("tele2YforInactive")));
		this.setIcon(5);
		
		dos.writeShort(this.getSceneID());			//SceneID
		StringUtil.writeUTF(dos, this.getName());	//Scene Name
		int flag = this.getIcon();
		flag|=getCanSelected()<<7;
		flag|=this.getSceneLock()<<6;
		dos.write(flag);							//scene icon|can selected|can lock
		dos.writeShort(this.getScreenX());	//scene x in worldmap
		dos.writeShort(this.getScreenY());	//scene y in worldmap

		Element ex;
		int i;
		WorldScence scn;

		NodeList nl = (NodeList) e.getElementsByTagName("Road");
		int count = 0;
		for (i = -1; ++i < nl.getLength();) {
			ex = (Element) nl.item(i);
			if (ex.getParentNode() != e)
				continue;
			count++;
		}
		dos.write(count);
		for (i = -1; ++i < nl.getLength();) {
			ex = (Element) nl.item(i);
			if (ex.getParentNode() != e)
				continue;
			Point.fromXML(ex, _pointPool, dos);
		}

		nl = (NodeList) e.getElementsByTagName("Scene");
		count = 0;
		for (i = -1; ++i < nl.getLength();) {
			ex = (Element) nl.item(i);
			if (ex.getParentNode() != e)
				continue;
			count++;
		}
		dos.write(count);
		for (i = -1; ++i < nl.getLength();) {
			ex = (Element) nl.item(i);
			if (ex.getParentNode() != e)
				continue;
			scn = new WorldScence();
			scn.fromXML(ex, scenePool, _pointPool, dos);
			scenePool.put(scn.getSceneID(), scn);
		}
	}
}
